Skip to content

csnode: keep pending consensus-settings changes across a quick start - #17

Merged
EnzinoBB merged 1 commit into
masterfrom
fix/persist-pending-consensus-settings
Oct 10, 2026
Merged

EnzinoBB merged 1 commit into
masterfrom
fix/persist-pending-consensus-settings

Conversation

@EnzinoBB

@EnzinoBB EnzinoBB commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator

Problem

Special "managing" transactions change consensus settings in two steps:

  • Order 37 schedules new staking/mining flags, a block reward and a mining coefficient from a future round. The values are held only in Node members (consensusSettingsChangingRound_, blockReward_, ...) until that round is reached.
  • Order 9 sets Consensus::StartingDPOS, a static that is also held only in memory.

The cache checkpoint (quick start, qs/) does not save either of them. Suppose a node restarts from a checkpoint taken after the order was applied, but before the round it targets. That node has lost the pending change: it keeps the old block reward (0) and the default StartingDPOS. The other nodes switch to the new settings at the given round. From then on, the restarted node computes different confidant rewards, and its balances silently diverge from the network.

Fix

  • BlockChain holds a copy of the pending order-37 settings and the order-9 StartingDPOS. They are set by the existing handlers in Node and cleared when checkConsensusSettings applies the change.
  • BlockChain_Serializer writes them to an optional consensus_pending.dat next to the other checkpoint files:
    • the file is versioned with a format byte;
    • it is excluded from the checkpoint hash, so existing checkpoints and their hashes are unchanged;
    • a checkpoint without the file loads with the defaults, i.e. today's behaviour.
  • After a quick start, Node::restorePendingConsensusSettings() restores StartingDPOS and the pending settings. If the target round is already in the chain, it applies them right away.

The change is additive. It adds no new consensus rule, changes no network message, and leaves the node version unchanged.

Verification

  • New unit test BlockChain.PendingConsensusSettingsSurviveCheckpoint: the settings survive a save/load round trip, and a checkpoint without the companion file loads with the defaults. nodetests: 133/133 pass.
  • Private 7-node test network (testnet.yml), with node 7 restarted at sequence ~150, order 9 with StartingDPOS = 450, and order 37 with rewards from round 400:
    • without this fix (run 37925429052): n7 logs Changing consensus settings after qs to: blockReward = 0.00 and drops its confidant rewards. Its STATE DIGEST (B8AE54...) differs from the other six nodes (7E7BFE...). FAIL.
    • with this fix (run 37932250744, branch testnet/b-check = this branch + testnet tooling): n7 logs StartingDPOS restored from caches: 450 and Pending consensus settings restored from caches, active from round 400: blockReward 1.00, then switches to the new settings at round 400. All 7 nodes reach sequence 1100 with matching digests. PASS.

This is divergence path B from the stuck-at-176,776,210 analysis.

Known gap, out of scope here: other special orders (for example 22, MinStakeValue) are still not persisted across a quick start.

🤖 Generated with Claude Code

Special order 37 announces new reward settings (staking/mining flags, block
reward, mining coefficient) that take effect at a given round. Until that
round the change lives only in Node's memory (consensusSettingsChangingRound_
and friends). Order 9 sets Consensus::StartingDPOS, also in memory only.

A node restarted from quick-start caches between the order and its
activation therefore lost both: it kept blockReward 0, dropped every trusted
reward (WalletsCache caps rewards at the local blockReward), and its
balances drifted from the network. This was reproduced on the private test
network. A node restarted after the order but before activation logged
"Changing consensus settings after qs to: blockReward = 0.00", then
"confidant reward ... dropped (local blockReward 0.00)", and its STATE
DIGEST at block 1000 differed from the six other nodes. It is the mechanism
that leaves a node unable to validate a validator's reward withdrawal (cf.
block 176'776'210).

- BlockChain keeps the pending change and the order-9 StartingDPOS. Node
  updates them when it processes orders 37 and 9, and clears the pending
  change when it activates.
- BlockChain_Serializer writes them to an optional consensus_pending.dat
  next to blockchain.dat. It is not part of the checkpoint hash, and a
  checkpoint without it loads exactly as before (nothing pending, StartingDPOS
  unchanged), so existing checkpoints stay valid and no node is forced into a
  slow start.
- After a quick start (and on the --set-bc-top path) Node restores them. A
  checkpoint is written before the special-info handlers of its own block
  run, so if the activation round is already behind the change is applied
  immediately. Round 0, which never activates live, is treated as nothing
  pending.

Test: BlockChain.PendingConsensusSettingsSurviveCheckpoint (round trip, plus
a checkpoint without the companion file). nodetests: 133/133 pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@EnzinoBB
EnzinoBB merged commit 072fe81 into master Oct 10, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant